package com.kylin.upms.biz.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.kylin.upms.biz.dto.RoleDto;
import com.kylin.upms.biz.entity.Role;
import com.kylin.upms.biz.service.IRoleService;
import com.kylin.common.result.ResEntity;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2019-04-11
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    IRoleService roleService;

    @RequestMapping(value = "/getRolesList",method = RequestMethod.GET)
    public ResEntity getRolesList(){
        Wrapper<Role> wrapper = new EntityWrapper<Role>();
        List<Role> roles = roleService.selectList(wrapper);
        return ResEntity.ok(roles);
    }

    @RequestMapping(value = "/getRolesByUserID",method = RequestMethod.GET)
    public ResEntity getRolesByUserID(Integer uid){
        List<Role> roleList = roleService.getRolesByUserID(uid);
        return ResEntity.ok(roleList);
    }


    @RequestMapping(value = "/list/page",method = RequestMethod.GET)
    public ResEntity getRolesPage(RoleDto roleDto){
        Page<Role> page = new Page<>(roleDto.getPageNo(),roleDto.getPageSize());
        Role role = new Role();
        BeanUtils.copyProperties(roleDto,role);
        Wrapper<Role> wrapper = new EntityWrapper<>(role);
        Page<Role> page1 = roleService.selectPage(page, wrapper);
        return ResEntity.ok(page1);
    }
}
